package com.zxl.yjb.activity.home.user;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zxl.yjb.R;
import com.zxl.yjb.activity.my.MyDataActivity;
import com.zxl.yjb.adapter.ImageAdapter;
import com.zxl.yjb.base.BaseActivity;
import com.zxl.yjb.bean.LocalMediaExtend;
import com.zxl.yjb.http.manager.DataManager;
import com.zxl.yjb.http.observer.ObserverOnNextListener;
import com.zxl.yjb.http.observer.ProgressObserver;
import com.zxl.yjb.widget.CircleImageView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class UserInfoActivity extends BaseActivity {


    @BindView(R.id.iv_back)
    ImageView iv_back;
    @BindView(R.id.tv_page_title)
    TextView tv_page_title;
    @BindView(R.id.iv_my_header)
    CircleImageView iv_my_header;
    @BindView(R.id.tv_nickname)
    TextView tv_nickname;
    @BindView(R.id.tv_gender)
    TextView tv_gender;
    @BindView(R.id.tv_birthday)
    TextView tv_birthday;
    @BindView(R.id.recycler)
    RecyclerView recycler;

    private String uid = "";
    private String nickname = "";
    private String headimage = "";
    private String sex = "";
    private String birthday = "";

    private ArrayList<String> imageList = new ArrayList<>();

    private ImageAdapter imageAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_userinfo);
        uid = getIntent().getStringExtra("uid");
        nickname = getIntent().getStringExtra("nickname");
        headimage = getIntent().getStringExtra("headimage");
        sex = getIntent().getStringExtra("sex");
        birthday = getIntent().getStringExtra("birthday");
        ButterKnife.bind(this);
        initView();
        getPhotoWall();
    }

    @Override
    protected void initView() {
        tv_page_title.setText("个人资料");
        Glide.with(UserInfoActivity.this).load(headimage).into(iv_my_header);
        tv_nickname.setText(nickname);

        tv_birthday.setText(birthday);

        switch (sex) {
        	case "0":
                tv_gender.setText("未知");
        		break;
        	case "1":
                tv_gender.setText("男");
        		break;
        	case "2":
                tv_gender.setText("女");
        		break;

        	default:
        		break;
        }

        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
        gridLayoutManager.setSmoothScrollbarEnabled(true);
        gridLayoutManager.setAutoMeasureEnabled(true);
        imageAdapter = new ImageAdapter(R.layout.item_image, imageList);
        recycler.setLayoutManager(gridLayoutManager);
        recycler.setHasFixedSize(true);

        recycler.setNestedScrollingEnabled(false);
        recycler.setAdapter(imageAdapter);


    }

    //获取照片墙
    private void getPhotoWall()
    {
        DataManager dataManager = new DataManager();
        Map<String,String> map = new HashMap<>();
        map.put("uid",uid);
        ObserverOnNextListener<ArrayList<String>> listener = new ObserverOnNextListener<ArrayList<String>>() {
            @Override
            public void onNext(ArrayList<String> strings) {
                imageList.addAll(strings);
                imageAdapter.notifyDataSetChanged();
            }
        };
        dataManager.photowall_list(new ProgressObserver<ArrayList<String>>(listener,UserInfoActivity.this),map);
    }


    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        finish();
    }
}
